//
//  ChangePwdController.m
//  DYLYJ
//
//  Created by JM on 15/11/23.
//  Copyright © 2015年 JM. All rights reserved.
//

#import "ChangePwdController.h"
#import "DYUIKit.h"
#import "DYRequestAll.h"
#import "AppDelegate.h"
@interface ChangePwdController ()
@property(nonatomic,strong)IBOutlet UITextField *oldPwdTextFeild;
@property(nonatomic,strong)IBOutlet UITextField *pwdTextFeild;
@property(nonatomic,strong)IBOutlet UITextField *pwdQueryTextFeild;
@end

@implementation ChangePwdController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}


- (IBAction)clickChangeBtn:(id)sender {
    [self.view endEditing:YES];
    if (self.oldPwdTextFeild.text.length == 0){
        [MJAlertView showMessage:@"请输入旧密码"];
        return;
    }
    if (self.pwdTextFeild.text.length == 0){
        [MJAlertView showMessage:@"请输入新密码"];
        return;
    }
    if (self.pwdQueryTextFeild.text.length == 0){
        [MJAlertView showMessage:@"请输入确认密码"];
        return;
    }
    
    if (![self.pwdTextFeild.text isEqualToString:self.pwdQueryTextFeild.text]){
        [MJAlertView showMessage:@"新密码不一致"];
        return;
    }
    ChangePwdRequest *request = [ChangePwdRequest request];
    request.DY_token = myAppDelegate.token;
    request.DY_oldPassword = self.oldPwdTextFeild.text;
    request.DY_newPassword = self.pwdTextFeild.text;
    [request requstWithCompletionHandler:^(DYResponse *rs, NSError *error) {
        if (error) {
            [MJAlertView showMessage:error.localizedDescription];
            return ;
        }
        [MJAlertView showAlertViewWithTitle:@"提示" message:@"修改成功" clickedButtonBlock:^(NSInteger index) {
              [self.navigationController popViewControllerAnimated:YES];
        } cancelButtonTitle:@"确定" otherButtonTitles:nil];
        
    }];
}
@end
